package com.panda.crud.logic.delete.auto.fill.config;

import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class MyTableNameHandler implements TableNameHandler {
    private static final Map<String, String> tableNames;

    static {
        tableNames = new HashMap<>();
        tableNames.put("2fdd1e29-5d62-cc72-f74f-1ba87e0821f6", "tbl_user");
        tableNames.put("0c8d0f75-21f2-0ddb-6e1b-e5d39cd9a10f", "tbl_tenant");
    }

    @Override
    public String dynamicTableName(String sql, String tableName) {
        if (sql.contains(tableName)) {
            String tblName = tableNames.get(tableName);
            if (StringUtils.isNoneBlank(tblName)) {
                return tblName;
            } else {
                throw new RuntimeException("表名" + tableName + "不存在");
            }
        } else {
            throw new RuntimeException("表名" + tableName + "不存在");
        }
    }
}
